package com.hdcircles.autoform.ui.label.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import com.hdcircles.autoform.R;
import com.hdcircles.autoform.app.Constants;
import com.hdcircles.autoform.base.SimpleActivity;
import com.hdcircles.autoform.model.bean.ChooseQuestionBean;
import com.hdcircles.autoform.model.bean.FormBean;
import com.hdcircles.autoform.model.bean.QuestionBean;
import com.hdcircles.autoform.ui.label.adapter.MouldAdapter;
import com.hdcircles.autoform.util.SharedPreferenceUtil;
import com.hdcircles.autoform.util.SystemUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hdcircles on 2016/11/22.
 */

public class FormMouldActivity extends SimpleActivity {


    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.rv_form_mould)
    RecyclerView rvFormMould;
    private List<FormBean> formBeanList;

    @Override
    protected int getLayout() {
        return R.layout.activity_question_mould;
    }

    @Override
    protected void initEventAndData() {
        setToolBar(toolbar,"选择模板");
        formBeanList=new ArrayList<>();
        MouldAdapter adapter=new MouldAdapter();
        rvFormMould.setLayoutManager(new LinearLayoutManager(this));
        rvFormMould.setAdapter(adapter);
        addDefaultData0();
        addDefaultData1();
        addDefaultData2();
        addDefaultData3();
        adapter.setFormBeanList(formBeanList);
        adapter.setItemClickListener(new MouldAdapter.onItemClickListener() {
            @Override
            public void onItemClick(FormBean formBean) {
                Bundle bundle=new Bundle();
                bundle.putParcelable("form",formBean);
                Intent intent=getIntent();
                intent.putExtras(bundle);
                setResult(Constants.TYPE_MOULD,intent);
                finish();
            }
        });
    }

    private void addDefaultData0(){
        FormBean defaultForm0=new FormBean();
        defaultForm0.setCreator(SharedPreferenceUtil.getUserEmail());
        defaultForm0.setFormName("特甲类-空铺中(默认)");
        defaultForm0.setTime(System.currentTimeMillis());
        defaultForm0.setStatus(Constants.STATUS_INITIALIZATION);
        defaultForm0.setFormId(SystemUtil.genID(System.currentTimeMillis()));
        List<QuestionBean> questionBeanList=new ArrayList<>();
        QuestionBean q0=new QuestionBean();
        q0.setType(Constants.TYPE_TEXT);
        q0.setQuestionTitle("行政区域");
        questionBeanList.add(q0);
        QuestionBean q1=new QuestionBean();
        q1.setQuestionTitle("主要人流");
        q1.setType(Constants.TYPE_MULTIPLE_CHOOSE);
        List<ChooseQuestionBean> chooseList0=new ArrayList<>();
        ChooseQuestionBean c0=new ChooseQuestionBean();
        c0.setInfo("学生");
        chooseList0.add(c0);
        ChooseQuestionBean c1=new ChooseQuestionBean();
        c1.setInfo("上班族");
        chooseList0.add(c1);
        ChooseQuestionBean c2=new ChooseQuestionBean();
        c2.setInfo("住户");
        chooseList0.add(c2);
        ChooseQuestionBean c3=new ChooseQuestionBean();
        c3.setInfo("行人");
        chooseList0.add(c3);
        q1.setChooseQuestion(chooseList0);
        questionBeanList.add(q1);
        QuestionBean q2=new QuestionBean();
        q2.setQuestionTitle("铺子地址");
        q2.setType(Constants.TYPE_LOCATION);
        questionBeanList.add(q2);
        QuestionBean q13=new QuestionBean();
        q13.setQuestionTitle("铺子照片");
        q13.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q13);
        QuestionBean q3=new QuestionBean();
        q3.setQuestionTitle("可使用空间");
        q3.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q3);
        QuestionBean q4=new QuestionBean();
        q4.setQuestionTitle("租金/月");
        q4.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q4);
        QuestionBean q5=new QuestionBean();
        q5.setQuestionTitle("转让费");
        q5.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q5);
        QuestionBean q6=new QuestionBean();
        q6.setQuestionTitle("可承租年限");
        q6.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q6);
        QuestionBean q7=new QuestionBean();
        q7.setQuestionTitle("200公尺半径圆內有无竞争店");
        q7.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q7);
        QuestionBean q14=new QuestionBean();
        q14.setQuestionTitle("200公尺半径圆內有无竞争店");
        q14.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q14);
        QuestionBean q8=new QuestionBean();
        q8.setQuestionTitle("预估营业额/日");
        q8.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q8);
        QuestionBean q9=new QuestionBean();
        q9.setQuestionTitle("首次拜访");
        q9.setType(Constants.TYPE_TIME);
        questionBeanList.add(q9);
        QuestionBean q10=new QuestionBean();
        q10.setQuestionTitle("第二次拜访");
        q10.setType(Constants.TYPE_TIME);
        questionBeanList.add(q10);
        QuestionBean q11=new QuestionBean();
        q11.setQuestionTitle("第三次拜访");
        q11.setType(Constants.TYPE_TIME);
        questionBeanList.add(q11);
        for (QuestionBean questionBean:questionBeanList){
            questionBean.setQuestionId(defaultForm0.getFormId()+questionBeanList.indexOf(questionBean));
        }
        defaultForm0.setQuestion(questionBeanList);
        formBeanList.add(defaultForm0);
    }

    private void addDefaultData1(){
        FormBean defaultForm0=new FormBean();
        defaultForm0.setCreator(SharedPreferenceUtil.getUserEmail());
        defaultForm0.setFormName("甲类-夫妻店(默认)");
        defaultForm0.setTime(System.currentTimeMillis());
        defaultForm0.setStatus(Constants.STATUS_INITIALIZATION);
        defaultForm0.setFormId(SystemUtil.genID(System.currentTimeMillis()));
        List<QuestionBean> questionBeanList=new ArrayList<>();
        QuestionBean q3=new QuestionBean();
        q3.setQuestionTitle("可使用空间");
        q3.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q3);
        QuestionBean q4=new QuestionBean();
        q4.setQuestionTitle("租金/月");
        q4.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q4);
        QuestionBean q5=new QuestionBean();
        q5.setQuestionTitle("转让费");
        q5.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q5);
        QuestionBean q6=new QuestionBean();
        q6.setQuestionTitle("可承租年限");
        q6.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q6);
        QuestionBean q7=new QuestionBean();
        q7.setQuestionTitle("200公尺半径圆內有无竞争店");
        q7.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q7);
        QuestionBean q14=new QuestionBean();
        q14.setQuestionTitle("200公尺半径圆內有无竞争店");
        q14.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q14);
        QuestionBean q8=new QuestionBean();
        q8.setQuestionTitle("预估营业额/日");
        q8.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q8);
        QuestionBean q9=new QuestionBean();
        q9.setQuestionTitle("首次拜访");
        q9.setType(Constants.TYPE_TIME);
        questionBeanList.add(q9);
        QuestionBean q10=new QuestionBean();
        q10.setQuestionTitle("第二次拜访");
        q10.setType(Constants.TYPE_TIME);
        questionBeanList.add(q10);
        QuestionBean q11=new QuestionBean();
        q11.setQuestionTitle("第三次拜访");
        q11.setType(Constants.TYPE_TIME);
        questionBeanList.add(q11);
        for (QuestionBean questionBean:questionBeanList){
            questionBean.setQuestionId(defaultForm0.getFormId()+questionBeanList.indexOf(questionBean));
        }
        defaultForm0.setQuestion(questionBeanList);
        formBeanList.add(defaultForm0);
    }

    private void addDefaultData2(){
        FormBean defaultForm0=new FormBean();
        defaultForm0.setCreator(SharedPreferenceUtil.getUserEmail());
        defaultForm0.setFormName("乙类-一般行业(默认)");
        defaultForm0.setTime(System.currentTimeMillis());
        defaultForm0.setStatus(Constants.STATUS_INITIALIZATION);
        defaultForm0.setFormId(SystemUtil.genID(System.currentTimeMillis()));
        List<QuestionBean> questionBeanList=new ArrayList<>();
        QuestionBean q0=new QuestionBean();
        q0.setType(Constants.TYPE_TEXT);
        q0.setQuestionTitle("行政区域");
        questionBeanList.add(q0);
        QuestionBean q1=new QuestionBean();
        q1.setQuestionTitle("主要人流");
        q1.setType(Constants.TYPE_MULTIPLE_CHOOSE);
        List<ChooseQuestionBean> chooseList0=new ArrayList<>();
        ChooseQuestionBean c0=new ChooseQuestionBean();
        c0.setInfo("学生");
        chooseList0.add(c0);
        ChooseQuestionBean c1=new ChooseQuestionBean();
        c1.setInfo("上班族");
        chooseList0.add(c1);
        ChooseQuestionBean c2=new ChooseQuestionBean();
        c2.setInfo("住户");
        chooseList0.add(c2);
        ChooseQuestionBean c3=new ChooseQuestionBean();
        c3.setInfo("行人");
        chooseList0.add(c3);
        q1.setChooseQuestion(chooseList0);
        questionBeanList.add(q1);
        QuestionBean q2=new QuestionBean();
        q2.setQuestionTitle("铺子地址");
        q2.setType(Constants.TYPE_LOCATION);
        questionBeanList.add(q2);
        QuestionBean q13=new QuestionBean();
        q13.setQuestionTitle("铺子照片");
        q13.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q13);
        QuestionBean q3=new QuestionBean();
        q3.setQuestionTitle("可使用空间");
        q3.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q3);
        QuestionBean q4=new QuestionBean();
        q4.setQuestionTitle("租金/月");
        q4.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q4);
        QuestionBean q5=new QuestionBean();
        q5.setQuestionTitle("转让费");
        q5.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q5);
        QuestionBean q6=new QuestionBean();
        q6.setQuestionTitle("可承租年限");
        q6.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q6);
        QuestionBean q7=new QuestionBean();
        q7.setQuestionTitle("200公尺半径圆內有无竞争店");
        q7.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q7);
        QuestionBean q14=new QuestionBean();
        q14.setQuestionTitle("200公尺半径圆內有无竞争店");
        q14.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q14);
        QuestionBean q8=new QuestionBean();
        q8.setQuestionTitle("预估营业额/日");
        q8.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q8);
        QuestionBean q9=new QuestionBean();
        q9.setQuestionTitle("首次拜访");
        q9.setType(Constants.TYPE_TIME);
        questionBeanList.add(q9);
        QuestionBean q10=new QuestionBean();
        q10.setQuestionTitle("第二次拜访");
        q10.setType(Constants.TYPE_TIME);
        questionBeanList.add(q10);
        QuestionBean q11=new QuestionBean();
        q11.setQuestionTitle("第三次拜访");
        q11.setType(Constants.TYPE_TIME);
        questionBeanList.add(q11);
        for (QuestionBean questionBean:questionBeanList){
            questionBean.setQuestionId(defaultForm0.getFormId()+questionBeanList.indexOf(questionBean));
        }
        defaultForm0.setQuestion(questionBeanList);
        formBeanList.add(defaultForm0);
    }


    private void addDefaultData3(){
        FormBean defaultForm0=new FormBean();
        defaultForm0.setCreator(SharedPreferenceUtil.getUserEmail());
        defaultForm0.setFormName("丙类-其他便利商店(默认)");
        defaultForm0.setTime(System.currentTimeMillis());
        defaultForm0.setStatus(Constants.STATUS_INITIALIZATION);
        defaultForm0.setFormId(SystemUtil.genID(System.currentTimeMillis()));
        List<QuestionBean> questionBeanList=new ArrayList<>();
        QuestionBean q0=new QuestionBean();
        q0.setType(Constants.TYPE_TEXT);
        q0.setQuestionTitle("行政区域");
        questionBeanList.add(q0);
        QuestionBean q1=new QuestionBean();
        q1.setQuestionTitle("主要人流");
        q1.setType(Constants.TYPE_MULTIPLE_CHOOSE);
        List<ChooseQuestionBean> chooseList0=new ArrayList<>();
        ChooseQuestionBean c0=new ChooseQuestionBean();
        c0.setInfo("学生");
        chooseList0.add(c0);
        ChooseQuestionBean c1=new ChooseQuestionBean();
        c1.setInfo("上班族");
        chooseList0.add(c1);
        ChooseQuestionBean c2=new ChooseQuestionBean();
        c2.setInfo("住户");
        chooseList0.add(c2);
        ChooseQuestionBean c3=new ChooseQuestionBean();
        c3.setInfo("行人");
        chooseList0.add(c3);
        q1.setChooseQuestion(chooseList0);
        questionBeanList.add(q1);
        QuestionBean q2=new QuestionBean();
        q2.setQuestionTitle("铺子地址");
        q2.setType(Constants.TYPE_LOCATION);
        questionBeanList.add(q2);
        QuestionBean q13=new QuestionBean();
        q13.setQuestionTitle("铺子照片");
        q13.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q13);
        QuestionBean q3=new QuestionBean();
        q3.setQuestionTitle("可使用空间");
        q3.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q3);
        QuestionBean q4=new QuestionBean();
        q4.setQuestionTitle("租金/月");
        q4.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q4);
        QuestionBean q5=new QuestionBean();
        q5.setQuestionTitle("转让费");
        q5.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q5);
        QuestionBean q6=new QuestionBean();
        q6.setQuestionTitle("可承租年限");
        q6.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q6);
        QuestionBean q7=new QuestionBean();
        q7.setQuestionTitle("200公尺半径圆內有无竞争店");
        q7.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q7);
        QuestionBean q14=new QuestionBean();
        q14.setQuestionTitle("200公尺半径圆內有无竞争店");
        q14.setType(Constants.TYPE_PICTURE);
        questionBeanList.add(q14);
        QuestionBean q8=new QuestionBean();
        q8.setQuestionTitle("预估营业额/日");
        q8.setType(Constants.TYPE_TEXT);
        questionBeanList.add(q8);
        QuestionBean q9=new QuestionBean();
        q9.setQuestionTitle("首次拜访");
        q9.setType(Constants.TYPE_TIME);
        questionBeanList.add(q9);
        QuestionBean q10=new QuestionBean();
        q10.setQuestionTitle("第二次拜访");
        q10.setType(Constants.TYPE_TIME);
        questionBeanList.add(q10);
        QuestionBean q11=new QuestionBean();
        q11.setQuestionTitle("第三次拜访");
        q11.setType(Constants.TYPE_TIME);
        questionBeanList.add(q11);
        for (QuestionBean questionBean:questionBeanList){
            questionBean.setQuestionId(defaultForm0.getFormId()+questionBeanList.indexOf(questionBean));
        }
        defaultForm0.setQuestion(questionBeanList);
        formBeanList.add(defaultForm0);
    }



}
